//
//  SABuyMessageCell.m
//  saasRetail
//
//  Created by mac on 2023/6/3.
//

#import "SABuyMessageCell.h"
#import "UILabel+NSMutableAttributedString.h"
#import "SASmsPackageListModel.h"

@interface SABuyMessageCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UILabel *saleLab;
@property (nonatomic, strong) UILabel *numLab;

@end

@implementation SABuyMessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SASmsPackageListModel *)model {
    _model = model;
    self.titleLab.text = model.name;
    self.contentLab.text = [NSString stringWithFormat:@"%ld条短信",model.smsCount];
    NSString *amount = [NSString stringWithFormat:@"%lf",model.amount / 100].getEffectivePointString;
    NSString *amountStr =  [NSString stringWithFormat:@"¥%@",amount];
    self.saleLab.text = [NSString stringWithFormat:@"售价%@元",amountStr];
    self.numLab.text = [NSString stringWithFormat:@"低至%0.2lf/元",model.amount / 100 /model.smsCount];
    
    [self.contentLab setAttributedStringWithSubString:@"条短信" color:kBlackColor font:kFont(15)];
    [self.saleLab setAttributedStringWithSubString:amountStr color:[UIColor redColor] font:kFont(22)];
    
    if (model.isSelect == YES) {
        self.bgView.layer.borderColor = [UIColor redColor].CGColor;
    }else {
        self.bgView.layer.borderColor = [UIColor whiteColor].CGColor;
    }
}

-(void)initUI {
    
    self.backgroundColor = kBgColor;
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.titleLab];
    [self.bgView addSubview:self.contentLab];
    [self.bgView addSubview:self.saleLab];
    [self.bgView addSubview:self.numLab];
    

    
}

-(UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIImageView alloc] initWithFrame:SARectMake(10, 0, kBaseScreenWidth - 20, 80)];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = kScaleNum(5);
        _bgView.layer.masksToBounds = YES;
        _bgView.userInteractionEnabled = YES;
        _bgView.layer.borderColor = [UIColor whiteColor].CGColor;
        _bgView.layer.borderWidth = 1;
    }
    return _bgView;
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(10, 15, 100, 15)];
        _titleLab.font = kBFont(12);
        _titleLab.textColor = kBlackColor;
        _titleLab.text = @"套餐一";
    }
    return _titleLab;
}

-(UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:SARectMake(10, 43, 200, 22)];
        _contentLab.font = kFont(22);
        _contentLab.textColor = [UIColor redColor];
        _contentLab.text = @"10000条短信";
    }
    return _contentLab;
}

-(UILabel *)saleLab {
    if (!_saleLab) {
        _saleLab = [[UILabel alloc] initWithFrame:SARectMake(220, 29, 120, 22)];
        _saleLab.font = kBFont(15);
        _saleLab.textColor = kBlackColor;
        _saleLab.text = @"售价600元";
        _saleLab.textAlignment = NSTextAlignmentRight;
    }
    return _saleLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(220, 55, 120, 15)];
        _numLab.font = kFont(12);
        _numLab.textColor = kLightgGrayColor;
        _numLab.text = @"低至0.06元";
        _numLab.textAlignment = NSTextAlignmentRight;
    }
    return _numLab;
}

@end
